from django.db import models
from user.models import User
from software.models import SoftwareVersion
from need.models import SoftwareNeed,NeedHandle
from question.models import SoftwareQuestion,QuestionHandle


# Create your models here.
class Announcement(models.Model):
    ANNOUNCEMENTUSERTYPE = (
        (1, u'开发人员通知'),
        (2, u'管理员通知'),
        (3, u'普通用户通知'),
    )
    ANNOUNCEMENTTYPE = (
        (1, u'software'),
        (2, u'need'),
        (3, u'question'),
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"用户",
        on_delete=models.CASCADE,
        related_name='user_announcement',
        null=True
    )
    softwareVersion = models.ForeignKey(
        SoftwareVersion,
        verbose_name=u"软件版本",
        on_delete=models.CASCADE,
        related_name='softwareVersion_announcement',
        null=True
    )
    isView = models.BooleanField(
        verbose_name=u'是否已读',
        default=False
    )
    announcementUserType = models.CharField(
        verbose_name=u'通知用户类型',
        choices=ANNOUNCEMENTUSERTYPE,
        max_length=20,
        default=u'',
    )
    IdNum = models.CharField(
        verbose_name=u'储存id',
        max_length=20,
        default=u'',
        null=True
    )
    announcementType = models.CharField(
        verbose_name=u'通知操作类型',
        choices=ANNOUNCEMENTTYPE,
        max_length=20,
        default=u'',
    )
    content = models.CharField(
        max_length=30,
        verbose_name=u'通知内容操作',
        default=u'',
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isRead = models.ManyToManyField(
        User,
        verbose_name=u"已阅读人员",
        # on_delete=models.CASCADE,
        related_name='user_isRead_announcement',
        # null=True
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.createTime

    class Meta:
        ordering = ('createTime',)
